<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\MyWeChat;

class Share extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
    }

    //首页
    public function index()
    {
        $this->assign("title", "邀请好友");
        $this->assign("foot_nav_index", "3");

        $user = $this->auth->getUser();
        // exit(print_r($user));
        if (!$user) {
            $this->redirect("/index/user/login");
        }

        $share_url = "http://" . $_SERVER["HTTP_HOST"] . "/index/user/register?code=" . $user->unique_id;
        // exit($share_url);

        // exit(print_r($user));
        if (!$user["avatar"]) {
            $user["avatar"] = $user["avatar"] ? cdnurl($user["avatar"]) : letter_avatar($user["nickname"]);
        }
        $this->assign("user", $user);

        $share_cover_list = config("site.sharepic");
        // exit(print_r($share_cover_list));
        $this->assign("share_cover_list", $share_cover_list);

        $this->assign("share_url", urlencode($share_url));
        $this->assign("share_url2", $share_url);


        return $this->view->fetch();
    }

    /**
     * 测试专用
     */
    public function test()
    {
        $wechat = new MyWeChat();
        $result = $wechat->app->jssdk->buildConfig([], true, false,  true);
        exit(print_r($result));
    }
}
